package com.eflow.engine.cmd;

import com.eflow.engine.event.FlowableEventBuilder;
import com.eflow.engine.service.ITaskService;
import com.eflow.engine.vo.JumpTaskVo;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

/**
 * @author hui se
 * @description
 * @create 2021-08-04 08:59
 **/
public class RejectedCmd implements Command<Void> {

    private JumpTaskVo jumpTaskVo;

    private ITaskService taskService;

    public RejectedCmd(JumpTaskVo jumpTaskVo, ITaskService taskService) {
        this.jumpTaskVo = jumpTaskVo;
        this.taskService = taskService;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        TaskEntity taskEntity = taskService.moveChange(jumpTaskVo);
        CommandContextUtil.getEventDispatcher().dispatchEvent(FlowableEventBuilder.createRejectedEventImplEvent(FlowableEngineEventType.CUSTOM, taskEntity),
                CommandContextUtil.getProcessEngineConfiguration().getEngineCfgKey());
        return null;
    }
}
